package org.jeecg.modules.quartz.job;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.TenantModel;
import org.jeecg.common.util.DateUtils;
import org.jeecg.config.mybatis.TenantContext;
import org.jeecg.modules.arc.service.IArcAccountService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 月末余额
 */

@Slf4j
public class AccMonthbalanceJob implements Job {

	@Autowired
	private IArcAccountService accountService;
	@Autowired
	private ISysBaseAPI baseAPI;
	/**
	 * 若参数变量名修改 QuartzJobController中也需对应修改
	 */
	//private String parameter;
	//
	//public void setParameter(String parameter) {
	//	this.parameter = parameter;
	//}

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

		log.info(String.format(" Boot 月末余额 AccMonthbalanceJob !  开始时间:" + DateUtils.getTimestamp()));

		//需要变量多租户
		List<TenantModel> tenantList = baseAPI.queryTenant();
		if(null != tenantList && tenantList.size()>0) {
			//遍历租户
			for (TenantModel tenantModel : tenantList) {
				TenantContext.setTenant(tenantModel.getId() + "");
				accountService.insertAccBalance();
			}
		}
		log.info(String.format(" Boot 月末余额 AccMonthbalanceJob !  结束时间:" + DateUtils.getTimestamp()));
	}

}
